package com.atguigu.dao.impl;

import com.atguigu.dao.DeployGoalDao;
import com.atguigu.pojo.DeployGoal;

import java.util.List;

public class DeployGoalDaoImpl extends BaseDao implements DeployGoalDao {
    @Override
    public int addDeployGoal(DeployGoal deployGoal) {
        System.out.println("DeployGoalDaoImpl 程序在["+Thread.currentThread().getName()+"]线程中");
        String sql="insert into t_deployGoal(`id`,`name`,`status`) values(?,?,?);";
            return update(sql,deployGoal.getId(),deployGoal.getName(),
                    deployGoal.getStatus());
    }

    @Override
    public int deleteDeployGoalById(String id) {
        String sql="delete from t_deployGoal where id=?";
        return update(sql,id);
    }

    @Override
    public int updateDeployGoal(DeployGoal deployGoal) {
        String sql="update t_deployGoal set `id`=?,`name`=?,`status`=? where id=?";
        return update(sql,deployGoal.getId(),
                deployGoal.getName(),deployGoal.getStatus(),
                deployGoal.getId());
    }

    @Override
    public DeployGoal queryDeployGoalById(String id) {
        String sql ="select `id`,`name`,`status` from t_deployGoal where id=?";
        return queryForOne(DeployGoal.class,sql,id);
    }

    @Override
    public List<DeployGoal> queryDeployGoals() {
        String sql ="select `id`,`name`,`status`  from t_deployGoal";
        return queryForList(DeployGoal.class,sql);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql="select count(*) from t_deployGoal";
        Number serverCount=(Number) queryForSingleValue(sql);//这个语句似乎可以返回任何类型的查询
        //System.out.println(bookCount);
        return serverCount.intValue();
    }

    @Override
    public List<DeployGoal> queryForPageItems(Integer begin, Integer pageSize) {
        String sql ="select `id`,`name`,`status`  from t_deployGoal limit ?,?";
        return queryForList(DeployGoal.class,sql,begin,pageSize);

    }
}
